 /* 
 *--------------------------------------------------------------------------
 *
 *      Serialflexer - Serial Class Library for Win32
 *      Copyright(C) 2008, Jiang Sanyi
 * 
 *      Contact Email: jiangsy@gmail.com
 * 
 * 
 *      This library is free software; you can redistribute it and/or
 *      modify it under the terms of the GNU Lesser General Public
 *      License as published by the Free Software Foundation; either
 *      version 2 of the License, or (at your option) any later version.
 * 
 *      This library is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *      Lesser General Public License for more details.
 * 
 *      You should have received a copy of the GNU Lesser General Public
 *      License along with this library in the file COPYING.LIB;
 *      if not, write to the Free Software Foundation, Inc.,
 *      59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 *
 * --------------------------------------------------------------------------
 */
/// 
/// iflexr.h: interface multiplexer header file
/// interface definitions for serial or other (such as socket) 
/// physical interface types.
#pragma once

typedef enum{
	ERROR_SetCommMask=100,//_T("SetCommMask")
	ERROR_WaitCommEvent,//_T("WaitCommEvent")
	ERROR_GetCommTimeouts,//_T("GetCommTimeouts")
	ERROR_EscapeCommFunctionSETDTR,//
	ERROR_EscapeCommFunctionCLRDTR,//(_T("EscapeCommFunction(CLRDTR)"));
	ERROR_SetCommTimeoutsRestoration,//(_T("SetCommTimeouts (Restoration to original)"));
	ERROR_PurgeComm,//(_T("PurgeComm"));
	ERROR_GetCommState,//(_T("GetCommState"));
	ERROR_SetCommState,//(_T("SetCommState"));
	ERROR_SetCommTimeouts,//(_T("SetCommTimeouts"));
	ERROR_GetCommModemStatus,//(_T("GetCommModemStatus"));
	ERROR_ClearCommError,//(_T("ClearCommError"));
	ERROR_WriteFile,//"WriteFile (in Writer)"
	ERROR_Write_timed_out_immediate,
	//
	ERROR_GetOverlappedResultInReader,
	ERROR_Max
};

/// SCB Interface: Serial Call Back Interface
class IDteCallBack
{
public:
	virtual DWORD SCBDataRecv(LPBYTE buffer, DWORD size) = 0;

	//	The TD (transmit data) wire is the one through which data from a DTE device is
	//transmitted to a DCE device. This name can be deceiving, because this wire is used by
	//a DCE device to receive its data. The TD line is kept in a mark condition by the DTE
	//device when it is idle. The RD (receive data) wire is the one on which data is received by
	//a DTE device, and the DCE device keeps this line in a mark condition when idle.
	//virtual DWORD SCBTransmitData();

	// 
	virtual void SCBComStat(BOOL fCtsHold, BOOL fDsrHold, 
		BOOL fRlsdHold, BOOL fXoffHold, BOOL fXoffSent, BOOL fEof, BOOL fTxim,
		BOOL cbOutQue, BOOL cbInQue) = 0;

	virtual void SCBStatusEvent(BOOL fCTS, BOOL fDSR, BOOL fERR, 
		BOOL fRING, BOOL fRLSD, BOOL fBREAK, BOOL fRXCHAR, 
		BOOL fRXFLAG, BOOL fTXEMPTY) = 0;

	virtual void SCBCommError(BOOL fDNS, BOOL fIOE, BOOL fOOP, 
		BOOL fPTO, BOOL fMODE, BOOL fBREAK, BOOL fFRAME, BOOL fRXOVER, 
		BOOL fTXFULL, BOOL fOVERRUN, BOOL fRXPARITY) = 0;

	// modem status change
	virtual void SCBModemStatus(BOOL fCTS, BOOL fDSR, BOOL fRING, BOOL fRLSD) = 0;

	// export error information
	// todo: use int as parameter. or make it like GetLastError()
	virtual void SCBErrorReporter( DWORD dwErrorCode/*TCHAR * szMessage*/ ) = 0;

	// a critical error is occured in communication
	virtual void SCBErrorInComm(void) = 0;

	// special status
	virtual void SCBReadAborted(void) = 0;
	virtual void SCBReadTimeoutOverlapped(void) = 0;
	virtual void SCBWaitCommEventAborted(void) = 0;
	virtual void SCBReatTimeoutImmediately(void) = 0;
};


//class IDteStatusError
//{
//public:
//	//
//	//  Error functions
//	//
//	virtual void ErrorReporter( TCHAR * szMessage ) = 0;
//	//virtual void ErrorHandler( TCHAR * szMessage ) = 0;
//	virtual void ErrorInComm( TCHAR * szMessage ) = 0;
//
//	//
//	//  Status functions
//	//
//	virtual void ReportStatusEvent(DWORD dwStatus) = 0;
//	virtual void CheckModemStatus( BOOL bUpdateNow) = 0;
//	virtual void ReportModemStatus(DWORD dwModemStatus) = 0;
//	virtual void ReportCommError( void ) = 0;
//	virtual void ReportComStat( COMSTAT ComStat ) = 0;
//	//virtual void StatusMessage( void ) = 0;
//	virtual void ReportStatus(char * szText) = 0;
//	virtual void CheckComStat( BOOL bUpdateNow) = 0;
//};